package com.gjm.order.service.impl;

import com.gjm.order.dao.objectdata.OrderInfo;
import com.gjm.order.dao.mapper.OrderMapper;
import com.gjm.order.dao.objectdata.ProductInfo;
import com.gjm.order.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderServiceImpl implements OrderService {

    @Resource(name = "orderMapper")
    private OrderMapper orderMapper;

    @Resource(name = "restTemplate")
    private RestTemplate restTemplate;

    @Override
    public OrderInfo getOrderInfoById(Integer orderId) {
        OrderInfo orderInfo = orderMapper.getOrderInfoById(orderId);

        String url = "http://127.0.0.1:9090/product/getProductInfoById?productId=" + orderInfo.getProductId();

        ProductInfo productInfo = restTemplate.getForObject(url, ProductInfo.class);

        orderInfo.setProductInfo(productInfo);

        return orderInfo;
    }
}
